<?php
class Merchant_Model_CustomerBalance
{
 
	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new Merchant_Model_DbTable_CustomerBalance();
	}
	/**
	*add DB Adapter  
	*/	
	public function getAdapter(){
		return $this->_table->getAdapter();
	}
	/**
	*add One Row  
	*@param array $row 
	*@return boolean
	*/
	public function add($row){
		return $this->_table->insert($row);
	}
	/**
	*Update One Row  
	*@param rowSet $row Customer's data 
	*@param int $customer_id 
	*@return boolean
	*/
	public  function update($row,$customerId){		
		$row['cb_last_update'] =  date("Y-m-d H:i:s");
		$where = $this->_table->getAdapter()->quoteInto('customer_id = ?', $customerId);

		return $this->_table->update($row, $where);
		
	}
		
	/**
	*Delete One Row
	*@param int $customer_id 
	*@return boolean
	*/
	public function delete($customerId){
	
		$where = $this->_table->getAdapter()->quoteInto('customer_id = ?', $customerId);		 
 
		return  $this->_table->delete($where);
		
	}
	/**
	*get by customer
	*@param int $customer_id 
	*@return boolean
	*/
	public function getByCustomer($customerId){ 
		$select = $this->_table->select()->where('customer_id = ?', $customerId);	 
		
		return $this->_table->fetchRow($select);
		 
	}	
	
	 
	
	public function getNumber(){
		$select = $this->_table->select()->from("customer_balance","count(*)");	
		return $this->_table->fetchOne($select);
	}
	
	public function lockForUpdate($customerId){		 
		$sql = "select * from customer_balance where customer_id='$customerId' for update";
		return $this->_table->getAdapter()->fetchRow($sql);
	}
	
}